<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- <link rel="stylesheet" href=""> -->
    <style>
        #demo {
            width: 200px;
            height: 200px;
            background-color: #6ff;
            margin: 50px;
        }

        form {
            margin-top: 10px;
        }
    </style>
</head>

<body>
    <div>
        <button class="get">获取</button>
        <button class="set">设置</button>
    </div>

    <form action="">
        <div class="input-group">
            <!-- 页面加载时 -->
            <!-- value => 初始值   disabled="disabled" 默认禁用  required="required" 默认必填   checked="checked" 默认选中  multiple="multiple" -->
            <label>用户名:<input type="text" name="user" placeholder="请输入..." value=""></label>
        </div>
        <div class="input-group">
            <label>密&emsp;码:<input type="password" name="pwd" placeholder="请输入..."></label>
        </div>
        <div class="input-group">
            <input type="checkbox" checked="checked" name="isChecked">阅读并接受《百度用户协议》、《儿童个人信息保护声明》及《百度隐私权保护声明》
        </div>
        <input type="submit" value="提交">
    </form>

    <!-- 类似 -->
    <!-- <video src="" controls loop autoplay muted></video> -->
</body>
<script>
    // value      获取和设置表单元素的值
    // disabled   获取和设置表单元素是否禁用 (true:禁用 false(默认):可用)
    // required   获取和设置表单元素是否必填 (true:必填 false(默认):选填)
    // checked    获取和设置表单元素是否选中(单选框,复选框)  (true:选中 false(默认):不选中)


    var getBtn = document.getElementsByClassName("get")[0]
    var setBtn = document.getElementsByClassName("set")[0]

    var userInp = document.getElementsByName("user")[0]
    var pwdInp = document.getElementsByName("pwd")[0]
    var isCheckInp = document.getElementsByName("isChecked")[0]

    getBtn.onclick = function () {
        console.log(userInp.disabled)
        console.log(pwdInp.required)
        console.log(isCheckInp.checked)
    }


    setBtn.onclick = function () {
        userInp.disabled = true;
        pwdInp.required = true;
        isCheckInp.checked = isCheckInp.checked ? false : true
    }



</script>

</html>